import React from 'react';
import { Route } from 'react-router-dom';
import { getToken } from 'utils/storage';

export default function newFunction(props) {
  const { path, component: Comp, ...rest } = props;
  return (
    <Route
      path={path}
      render={(_props) => {
        if (getToken()) {
          return <Comp {..._props} {...rest} />;
        }
        _props.history.push('/login');
      }}
    />
  );
}
